<template>
  <div class="d_main">
    <!-- <printOrder
        ref="print"
        :product-from="printOrderInfo"
        :productdd="rowData"
        :detailFrom="detailFrom"
      ></printOrder> -->
    <na-table
      :datas.sync="tableData"
      :searchObj.sync="search"
      @updateDatas="getAllMaterils"
      @selection-change="handleSelectionChange"
      @checkboxChange="handleCheckboxChange"
      @finishChange="handleFinishChange"
    >
      <template #slotSearch>
        <div class="flex ml16">
          <!-- <div>日期范围：</div> -->
          <el-date-picker
            v-model="valueDate"
            style="width: 100%"
            size="small"
            type="daterange"
            range-separator="-"
            value-format="yyyy-MM-dd"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="handleDateChange"
          >
          </el-date-picker>
        </div>
        <div class="flex ml16">
          <!-- <div>单据状态：</div> -->
          <el-select v-model="search.ProduceBillState" @change="getAllMaterils" size="small" filterable placeholder="请选择单据状态">
            <el-option
              v-for="item in djStateOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div class="flex ml16">
          <!-- <div>领料状态：</div> -->
          <el-select v-model="search.MaterialState" @change="getAllMaterils" size="small" filterable placeholder="请选择领料状态">
            <el-option
              v-for="item in llStateOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div class="flex ml16">
          <!-- <div>生产状态：</div> -->
          <el-select v-model="search.TaskProduceState" @change="getAllMaterils" size="small" filterable placeholder="请选择生产状态">
            <el-option
              v-for="item in scStateOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </div>
      </template>
      <template #slot1>
        <el-dropdown class="mr8">
          <el-button type="primary" size="small">
            新建<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="newAddClick(1)"
            >生产</el-dropdown-item
            >
            <!-- <el-dropdown-item @click.native="newAddClick(2)"
              >补单</el-dropdown-item
            > -->
            <el-dropdown-item @click.native="newAddClick(3)"
            >测试</el-dropdown-item
            >
            <el-dropdown-item @click.native="newAddClick(4)"
            >调机</el-dropdown-item
            >
            <el-dropdown-item @click.native="newAddClick(5)"
            >打样</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
        <el-button
          @click="pullListCheck1"
          size="small"
          v-permission="'MenuCode2-1-9'"
        >批量领料</el-button
        >
        <!-- <el-button
          @click="pullListCheck"
          size="small"
          v-permission="'MenuCode2-1-9'"
          >批量领料</el-button
        > -->
      </template>
    </na-table>
    <orderList
      :per-visible.sync="showOrder"
      @current="selectCurrentRow"
    ></orderList>
    <div class="printBox">
      <printOrder
        ref="print"
        :product-from="printOrderInfo"
        :productdd="rowData"
        :detailFrom="detailFrom"
        :productInfo="productInfo"
      ></printOrder>
    </div>
    <per-redio-dialog
      :per-visible.sync="isperShow"
      @getEmployee="getEmployee"
    />
    <!-- 批量领料 -->
    <el-dialog
      :title="'申请领料'"
      :visible.sync="isAddProduct"
      :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog"
      width="85%"
      @open="openCp"
    >
      <div class="dialogDody">
        <div class="subTip">
          <span class="mr15"
          ><span class="mr5">缴库单号：</span
          >{{ ProductForm.handInBillNo || "系统自动生成" }}</span
          >
          <span class="mr15"
          ><span class="mr5">创建日期：</span
          >{{ ProductForm.createDate || dayjs().format("YYYY-MM-DD") }}</span
          >
          <span
          ><span class="mr5">创建人员：</span
          >{{
              ProductForm.createPersonName ? ProductForm.createPersonName : name
            }}</span
          >
        </div>
        <div class="addWuliaoBox">
          <el-form
            ref="SCLLForm"
            :model="SCLLForm"
            :rules="llrules"
            label-width="110px"
            label-position="left"
            class="dialogForm dialogInlineForm"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item label="领料人员" prop="getMaterialPerson">
                  <div class="flex flex_center">
                    <div class="flex1">
                      <el-input
                        v-model="SCLLForm.getMaterialName"
                        size="mini"
                        placeholder="请选择人员"
                        disabled
                      >
                        <!-- <el-button
                          slot="append"
                          disabled
                          icon="el-icon-user"
                          @click="isperShow = true"
                        /> -->
                      </el-input>
                    </div>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="领料备注" class="getMaterialRemark">
              <el-input
                v-model="SCLLForm.getMaterialRemark"
                type="textarea"
                :rows="3"
                placeholder="领料备注"
                size="mini"
                clearable
              />
            </el-form-item>
          </el-form>
          <div class="tableBox">
            <div class="tt flex flex_between">
              <span class="fw">申请领料明细</span>
            </div>
            <div class="tagCon">
              <div
                v-for="item in LLform"
                :key="item.productTagCode"
                class="tagList"
              >
                <div class="listNav flex">
                  <span class="pointer tagright" @click="shrink(item)">
                    <i v-if="!item.isShow" class="el-icon-arrow-down" />
                    <i v-else class="el-icon-arrow-up" />
                  </span>
                  <span class="f14 mlr15"
                  >生产单号: {{ item.billBaseData.produceTaskBillNo }}</span
                  >
                  <span class="f14 mlr15"
                  >生产类型: {{ item.billBaseData.produceBillTypeName }}</span
                  >
                  <span class="f14 mlr15"
                  >订单单号: {{ item.billBaseData.xieYiShuHao }}</span
                  >
                  <span class="f14 mlr15"
                  >产品名称: {{ item.billBaseData.orderProductName }}</span
                  >
                  <span class="f14 mlr15"
                  >计划用料: {{ item.billBaseData.plannedMaterials }}</span
                  >
                </div>
                <div v-show="!item.isShow" class="tagShow">
                  <el-table
                    :data="item.wlMxDataList"
                    style="width: 100%"
                    :show-header="true"
                  >
                    <el-table-column
                      prop="stockGoodsCode"
                      label="物料编码"
                      align="center"
                      width="144"
                    />
                    <el-table-column
                      prop="categoryName"
                      label="物料类型"
                      align="center"
                      width="144"
                    />
                    <el-table-column
                      prop="supplierName"
                      label="供应商"
                      align="center"
                      width="144"
                    />
                    <el-table-column
                      prop="goodsName"
                      label="物料名称"
                      align="center"
                      width="134"
                    />
                    <el-table-column
                      prop="stockGoodsName"
                      label="规格型号"
                      align="center"
                      width="144"
                    />
                    <el-table-column
                      prop="planMaterialQuantity"
                      label="领料数量"
                      align="center"
                      width="134"
                    />
                    <el-table-column
                      prop="goodsUnitName"
                      label="物料单位"
                      align="center"
                      width="134"
                    />
                    <el-table-column
                      prop="equipmentName"
                      label="领料机台"
                      align="center"
                      width="144"
                    />
                    <el-table-column
                      prop="produceMaterialRemark"
                      label="备注"
                      align="center"
                      width="auto"
                    />
                  </el-table>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isAddProduct = false">取 消</el-button>
        <!-- 新增       -->
        <el-button
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="saveLL"
        >保存</el-button
        >
      </div>
    </el-dialog>
    <!-- 停工原因   -->
    <el-dialog
      :title="'原因'"
      :visible.sync="stopVisible"
      :close-on-click-modal="false"
      custom-class="comDialog"
      append-to-body
      width="30%"
      @close="closeStopDialog"
    >
      <div class="dialogDody">
        <el-form
          ref="cancelForm"
          :model="cancelForm"
          label-width="0px"
          class="dialogForm"
        >
          <el-form-item label="" prop="reason">
            <el-input
              v-model="cancelForm.stopWorkReason"
              type="textarea"
              :autosize="{ minRows: 5 }"
              placeholder="请输入内容"
              size="mini"
              clearable
            />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="stopVisible = false">取 消</el-button>
        <el-button
          :loading="addLableLoading"
          :disabled="addLableLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="saveStop"
        >保存</el-button
        >
      </div>
    </el-dialog>
    <!-- 作废原因   -->
    <el-dialog
      :title="'原因'"
      :visible.sync="reasonVisible"
      :close-on-click-modal="false"
      custom-class="comDialog"
      append-to-body
      width="30%"
      @close="closeCancelDialog"
    >
      <div class="dialogDody">
        <el-form
          ref="cancelForm"
          :rules="cancelFormrules"
          :model="cancelForm"
          label-width="0px"
          class="dialogForm"
        >
          <el-form-item label="" prop="cancelReason">
            <el-input
              v-model="cancelForm.cancelReason"
              type="textarea"
              :autosize="{ minRows: 5 }"
              placeholder="请输入内容"
              size="mini"
              clearable
            />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="reasonVisible = false">取 消</el-button>
        <el-button
          :loading="addLableLoading"
          :disabled="addLableLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="saveReason"
        >保存</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
import naTable from "@/components/naTable";
import Pagination from "@/components/Pagination";
import HeadSeting from "@/components/HeadSeting";
import screec from "@/components/screen";
import orderList from "./components/orderList.vue";
import printOrder from "./components/printT.vue";
import { mapGetters } from "vuex";
import { arraySort } from "@/utils";
import perRedioDialog from "@/components/perDialogRedio";
export default {
  inject: ["reload"],
  name: "productionOrderNew",
  components: {
    Pagination,
    HeadSeting,
    perRedioDialog,
    screec,
    naTable,
    orderList,
    printOrder,
  },
  data() {
    return {
      ops: "cancelOrder",
      addLableLoading: false,
      reasonVisible: false, // 原因弹框是否打开
      searchLoading: false, // 业务开单列表加载效果
      isShowOption: false,
      showOrder: false,
      isAddProduct: false, //批量领料弹出层状态
      isperShow: false,
      valueDate:'',
      LLform: [],
      pullList: [],
      djStateOptions:[{
        value: 0,
        label: '待确认'
      },{
        value: 1,
        label: '已确认'
      },{
        value: 2,
        label: '已作废'
      },{
        value: -1,
        label: '全部'
      },],
      llStateOptions:[{
        value: 0,
        label: '待领料'
      },{
        value: 1,
        label: '已领料'
      },{
        value: -1,
        label: '全部'
      }],
      scStateOptions:[{
        value: 0,
        label: '待生产'
      },{
        value: 1,
        label: '生产中'
      },{
        value: 2,
        label: '待停工'
      },{
        value: 3,
        label: '已停工'
      },{
        value: 4,
        label: '已完成'
      },{
        value: -1,
        label: '全部'
      }],
      ProductForm: {},
      SCLLForm: {
        getMaterialName: "",
        getMaterialPerson: "",
        getMaterialRemark: "",
      },
      llrules: {
        getMaterialPerson: [
          { required: true, message: "请选择人员", trigger: "change" },
        ],
      },
      // 搜索条件
      search: {
        QueryDataBaseFiled: "",
        pageIndex: 1,
        pageSize: 500,
        likeWords: "",
        isShowCancelBills: false,
        BeginTime:'',
        EndTime:'',
        ProduceBillState:'',
        MaterialState:'',
        TaskProduceState:'',
        isShowCompleteBills:true,
      },
      rowData: null, //列表行数据
      detailFrom: {},
      productInfo:{}, //产品信息
      tableData: {
        headId: "head", //表头列显隐组件所需ID-避免多个页面id重复问题
        tableId: "produceTaskID", //表格列表key,也就是一条数据的唯一标识
        senior: false, //高级搜索是否显示
        isShowFinish:false,
        disableWord: "", //是否禁用显示的字段
        disableStatus: "", //判断未禁用的状态值
        addTitle: "",
        //voidWord: "isShowCancelBills",
        finish: "isShowCompleteBills",
        select: true, //多选
        isDisabled: false, //是否禁用多选框
        //表格按钮
        operationBtn: [
          {
            title: "查看",
            methodsName: "showProduct",
          },
          {
            title: "编辑",
            methodsName: "handleUpdata",
            permission: "MenuCode2-1-2",
            hideCondition: {
              //按钮显隐条件
              prop: "isEdit", //控制显隐的状态字段
              show: [
                //有哪些状态
                1
              ],
            },
          },
          // {
          //   title: "删除",
          //   methodsName: "handleDelete",
          //   permission: "MenuCode2-1-3",
          //   hideCondition: {
          //     //按钮显隐条件
          //     prop: "produceBillState", //控制显隐的状态字段
          //     show: [
          //       //有哪些状态
          //       0,
          //     ],
          //   },
          // },
          {
            title: "确认",
            methodsName: "handleConfirm",
            permission: "MenuCode2-1-4",
            hideCondition: {
              //按钮显隐条件
              prop: "produceBillState", //控制显隐的状态字段
              show: [
                //有哪些状态
                0,
              ],
            },
          },
          {
            title: "生产补单",
            methodsName: "handleFixm",
            permission: "MenuCode2-1-7",
            hideCondition: {
              //按钮显隐条件
              prop: "produceBillState", //控制显隐的状态字段
              show: [
                //有哪些状态
                1, 4,
              ],
            },
          },
          {
            title: "撤回",
            methodsName: "handleRevocatio",
            permission: "MenuCode2-1-10",
            hideCondition: {
              //按钮显隐条件
              prop: "withdraw", //控制显隐的状态字段
              show: [
                //有哪些状态
                1,
              ],
            },
          },
          {
            title: "生产完成",
            methodsName: "handleDone",
            permission: "MenuCode2-1-5",
            hideCondition: {
              //按钮显隐条件
              prop: "taskProduceState", //控制显隐的状态字段
              show: [
                //有哪些状态
                1,
              ],
            },
          },
          {
            title: "撤销完成",
            methodsName: "handleRevoke",
            permission: "",
            hideCondition: {
              //按钮显隐条件
              prop: "taskProduceState", //控制显隐的状态字段
              show: [
                //有哪些状态
                4,
              ],
            },
          },
          {
            title: "作废",
            methodsName: "handleCancelCheck",
            permission: "",
            isShowCheckbox: true,
            hideCondition: {
              //按钮显隐条件
              prop: "isViod", //控制显隐的状态字段
              show: [
                //有哪些状态
                1,
              ],
            },
          },
          {
            title: "停工",
            methodsName: "handleStop",
            permission: "MenuCode2-1-6",
            hideCondition: {
              //按钮显隐条件
              prop: "produceBillState", //控制显隐的状态字段
              show: [
                //有哪些状态
                2, 1,
              ],
            },
          },
          {
            title: "复制",
            methodsName: "handleReCopy",
            permission: "",
          },
          {
            title: "打印生产通知单",
            methodsName: "handleDownload",
          },
          {
            title: "打印工序质量流转卡",
            methodsName: "handleDownloadCard",
          },
        ],
        //表格内容
        tbody: [],
        //表格表头
        thead: [],
      },
      productType: 0,
      printOrderInfo: {
        // baseData:{
        //   xieYiShuHao:''
        // }
      }, //订单信息
      currentItem: null,
      toolShow: true,
      stopVisible: false,
      cancelForm: {
        cancelReason: "",
        stopWorkReason: "",
      },
      total: 0,
      allMaterirls: [],
      tableHead: [],
      tableScreenHead: [],
      tableHeight: null,
      cancelFormrules: {
        cancelReason: [
          { required: true, message: "请输入原因", trigger: "change" },
        ],
      },
      rules: {
        reason: [
          {
            required: true,
            message: "请填写原因",
            trigger: ["change", "blur"],
          },
        ],
      },
    };
  },
  computed: {
    ...mapGetters(["name", "userInfo"]),
  },
  created() {
    // 业务开单列表表格表头
    this.getTableHead();
    //  所有列表数据
    this.getAllMaterils();
  },
  mounted() {},

  methods: {
    //新建
    newAddClick(type) {
      this.productType = type;
      this.showOrder = true;
    },

    //订单选择事件
    selectCurrentRow(row) {

      let routeUrl = this.$router.resolve({
            path: "/production/productionOrderNewDetail",
            query: {
              orderNo: row.orderNo,
              produceBillState:row.produceBillState,
              oldSaleOrderNo: row.oldOrderNo,
              saleOrderCode: row.saleOrderCode,
              taskProduceState:row.taskProduceState,
              printingSurface: row.printingSurface,
              productType: this.productType,
              productCode: row.productNo,
              createPersonName: row.createOrderPerson,
              typeStatus: 0,
              },
            });
        window.open(routeUrl.href, '_blank');

      // this.$router.push({
      //   path: "/production/productionOrderNewDetail", // 跳转的路径
      //   query: {
      //     orderNo: row.orderNo,
      //     oldSaleOrderNo: row.oldOrderNo,
      //     saleOrderCode: row.saleOrderCode,
      //     printingSurface: row.printingSurface,
      //     productType: this.productType,
      //     productCode: row.productNo,
      //     createPersonName: row.createOrderPerson,
      //     typeStatus: 0,
      //   },
      // });
    },

    //打印
    handlePrint(row) {
      this.rowData = row;
      this.$refs.print.setCode(row);
      this.getOrderInfo(row);
    },

    //作废选择事件
    handleCheckboxChange() {
      this.search.pageIndex = 1;
      this.getAllMaterils();
    },

    handleFinishChange(e){
      this.search.pageIndex = 1;
      this.getAllMaterils();
    },

    //获取订单详情
    getOrderDetail(row) {
      let parmas = {
        produceTaskID: row.produceTaskID,
        produceTaskBillNo: "",
      };
      this.$api.product.GetProduceTaskBillDetail(parmas).then((res) => {
        this.detailFrom = res;
        this.$refs.print.showDetail = true;
        this.$refs.print.showModel = true;
        setTimeout(() => {
          this.$print(this.$refs.print, {
            onPrint: ".noPrint",
            onStart: () => {
              console.log("打印开始");
            },
            onEnd: () => {
              console.log("打印完成");
            },
          });
          this.$refs.print.showModel = false;
        }, 100);
      });
    },

    //日期范围选择事件
    handleDateChange() {
      if (this.valueDate) {
        this.search.BeginTime = this.valueDate[0];
        this.search.EndTime = this.valueDate[1];
      } else {
        this.search.BeginTime = "";
        this.search.EndTime = "";
      }
      this.getAllMaterils();
    },

    //获取订单信息
    getOrderInfo(row) {
      const parmas = {
        saleOrderGroupCode: row.saleOrderNo,
        saleOrderCode: row.saleOrderCode,
      };
      this.$api.business
        .GetSaleOrderGroupDetail(parmas)
        .then((res) => {
          this.printOrderInfo = res;
          this.getOrderDetail(row);
          this.getProductDetail(row.productNo)
        })
        .catch(() => {});
    },

    //获取产品详情
    getProductDetail(id) {
      const parmas = {
        queryBy: 2,
        queryValue: id,
      };
      this.$api.business.GetSingleProductByProductCode(parmas).then((res) => {
        this.productInfo = res;
      });
    },

    // 修改
    handleUpdata(row) {
      let routeUrl = this.$router.resolve({
            path: "/production/productionOrderNewDetail",
            query: {
              produceBillState:row.produceBillState,
                produceTaskBillNo: row.produceTaskBillNo,
                produceTaskID: row.produceTaskID,
                taskProduceState:row.taskProduceState,
                type: row.produceBillTypeName,
                productCode: row.productNo,
                createPersonName: row.createPersonName,
                typeStatus: 2,
              },
            });
        window.open(routeUrl.href, '_blank');
      // console.log(row);
      // this.$router.push({
      //   path: "/production/productionOrderNewDetail", // 跳转的路径
      //   query: {
      //     produceTaskBillNo: row.produceTaskBillNo,
      //     produceTaskID: row.produceTaskID,
      //     type: row.produceBillTypeName,
      //     productCode: row.productNo,
      //     createPersonName: row.createPersonName,
      //     typeStatus: 2,
      //   },
      // });
    },
    // 查看
    showProduct(row) {
      console.log(row);
      let routeUrl = this.$router.resolve({
            path: "/production/productionOrderNewDetail",
            query: {
              produceTaskBillNo: row.produceTaskBillNo,
              produceBillState:row.produceBillState,
              produceTaskID: row.produceTaskID,
              taskProduceState:row.taskProduceState,
              productCode: row.productNo,
              createPersonName: row.createPersonName,
              typeStatus: 1,
              },
            });
        window.open(routeUrl.href, '_blank');
      // this.$router.push({
      //   path: "/production/productionOrderNewDetail", // 跳转的路径
      //   query: {
      //     produceTaskBillNo: row.produceTaskBillNo,
      //     produceTaskID: row.produceTaskID,
      //     productCode: row.productNo,
      //     createPersonName: row.createPersonName,
      //     typeStatus: 1,
      //   },
      // });
    },

    getEmployee(val) {
      this.SCLLForm.getMaterialPerson = val.employeeCode;
      this.SCLLForm.getMaterialName = val.employeeName;
    },

    openCp() {
      this.SCLLForm = {
        getMaterialName: this.userInfo.employeeName,
        getMaterialPerson: this.userInfo.employeeCode,
        getMaterialRemark: "",
      };
      const _nos = [];
      this.pullList.forEach((e) => {
        _nos.push(e.produceTaskBillNo);
      });
      this.$api.product
        .GetMoreProduceTaskMaterialList({
          produceTaskBillNos: _nos,
        })
        .then((res) => {
          this.LLform = res;
        })
        .catch(() => {});
    },

    //多选选择事件
    handleSelectionChange(val) {
      console.log(val);
      this.pullList = val;
    },

    pullListCheck1(){
      if (this.pullList.length <= 0) {
        this.$message({
          type: "error",
          message: "请选择生产单!",
        });
        return;
      }
      this.isAddProduct = true
    },

    pullListCheck() {
      if (this.pullList.length <= 0) {
        this.$message({
          type: "error",
          message: "请选择生产单!",
        });
        return;
      }
      // console.log(this.pullList)
      // return
      let arr = this.pullList.map((x)=>{
        return x.produceTaskBillNo
      })

      this.$confirm("是否批量领料选中数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$api.product.BatchCreateGetProduceMaterialBills({produceTaskBillNoList:arr}).then(()=>{
          this.$message.success('操作成功')
          this.getAllMaterils();
        })
      });


      // this.isAddProduct = true;
    },

    //下载
    handleDownload(row) {
      let parmas = {
        templateTypeCode: "MBLX0002", //	模板类型编号
        customerCode: row.customerCode, //	客户编号
        condition: {
          ProductCode:row.productNo,  //产品编号
          SaleOrderCode:row.saleOrderCode,
          ProduceTaskBillNo: row.produceTaskBillNo,
        }, //查询条件
      };
      this.$api.system.DownLoadTemplate(parmas).then((res) => {
        this.$api.system.UpdateProduceNoticeBillDownloaded({produceTaskBillNo:row.produceTaskBillNo}).then((res)=>{
          this.getAllMaterils();
        })
        window.open(res);
      });
    },

    //下载流转卡
    handleDownloadCard(row){
      let parmas = {
        templateTypeCode: "MBLX0003", //	模板类型编号
        customerCode: row.customerCode,
        condition: {
          ProduceTaskBillNo: row.produceTaskBillNo,
        }, //查询条件
      };
      this.$api.system.DownLoadTemplate(parmas).then((res) => {
        window.open(res);
      });
    },

    //批量领料
    saveLL() {
      this.$refs.SCLLForm.validate((valid) => {
        if (valid) {
          let arr = this.pullList.map((x)=>{
            return x.produceTaskBillNo
          })
          let obj = {
            remark:this.SCLLForm.getMaterialRemark,
            produceTaskBillNoList:arr
          }
          this.$api.product.BatchCreateGetProduceMaterialBills(obj).then(()=>{
            this.$message.success('操作成功')
            this.isAddProduct = false
            this.getAllMaterils();
          })
          // const parmas = Object.assign({}, this.SCLLForm);
          // const _arr = [];
          // this.LLform.forEach((e) => {
          //   e.wlMxDataList.forEach((wl) => {
          //     var _data = {};
          //     var _wlMxDataList = [];
          //     wl.applyGetQuantity = wl.planMaterialQuantity;
          //     wl.getMaterialRemark = wl.produceMaterialRemark;
          //     _data.saleOrderNo = e.billBaseData.saleOrderNo;
          //     _data.produceTaskBillNo = e.billBaseData.produceTaskBillNo;
          //     _data.equipmentNo = wl.equipmentNo;
          //     // var a = e.wlMxDataList.find(item => item.equipmentNo === wl.equipmentNo)
          //     _wlMxDataList.push(wl);
          //     _data.mxDataList = _wlMxDataList;
          //     _arr.push(_data);
          //   });
          // });
          // parmas.billDataList = _arr;
          // this.addProductLoading = true;
          // this.$api.product
          //   .CreateMoreGetProduceMaterialBills(parmas)
          //   .then(() => {
          //     this.addProductLoading = false;
          //     this.isAddProduct = false;
          //     this.getAllMaterils();
          //     this.$message({
          //       message: "保存成功",
          //       type: "success",
          //     });
          //   })
          //   .catch(() => {
          //     this.addProductLoading = false;
          //   });
        }
      });
    },

    // 报废
    saveReason() {
      this.$refs.cancelForm.validate((valid) => {
        if (valid) {
          this.$api.product
            .CancelProduceTaskBill({
              produceTaskID: this.currentItem.produceTaskID,
              cancelReason: this.cancelForm.cancelReason,
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "报废成功!",
              });
              this.reasonVisible = false;
              this.getAllMaterils();
            })
            .catch(() => {});
        }
      });
    },

    // 停工
    saveStop() {
      this.$api.product
        .StopProduceTaskBill({
          produceTaskID: this.currentItem.produceTaskID,
          cancelReason: this.cancelForm.stopWorkReason,
        })
        .then((res) => {
          this.$message({
            type: "success",
            message: "停工成功!",
          });
          this.stopVisible = false;
          this.getAllMaterils();
        })
        .catch(() => {});
    },

    closeStopDialog() {
      this.stopVisible = false;
    },

    // 补单
    handleFixm(row) {
      let routeUrl = this.$router.resolve({
            path: "/production/productionOrderNewDetail",
            query: {
              produceBillState:row.produceBillState,
                produceTaskBillNo: row.produceTaskBillNo,
                produceTaskID: row.produceTaskID,
                type: row.produceBillTypeName,
                taskProduceState:row.taskProduceState,
                productCode: row.productNo,
                createPersonName: row.createPersonName,
                typeStatus: 4,
              },
            });
        window.open(routeUrl.href, '_blank');
      // this.$router.push({
      //   path: "/production/productionOrderNewDetail", // 跳转的路径
      //   query: {
      //     produceTaskBillNo: row.produceTaskBillNo,
      //     produceTaskID: row.produceTaskID,
      //     type: row.produceBillTypeName,
      //     productCode: row.productNo,
      //     createPersonName: row.createPersonName,
      //     typeStatus: 4,
      //   },
      // });
    },

    // 确认订单
    handleConfirm(item) {
      this.$confirm("是否确认生产单?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        const parmas = {
          produceTaskID: item.produceTaskID,
        };
        this.$api.product
          .SureProduceTaskBill(parmas)
          .then((res) => {
            this.$message.success("确认成功");
            this.getAllMaterils();
          })
          .catch(() => {});
      });
    },

    // 撤回
    handleRevocatio(item) {
      this.$confirm("是否确定撤回该生产单?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$api.product
          .RevocationProduceTaskBill({
            produceTaskID: item.produceTaskID,
          })
          .then((res) => {
            this.$message({
              type: "success",
              message: "撤回成功!",
            });
            this.getAllMaterils();
          })
          .catch(() => {});
      });
    },

    // 完成生产
    handleDone(item) {
      let lable = "";
      if (item.progress != 100) {
        lable = "生产单据下还有未完成的作业是否继续完成?";
      } else {
        lable = "是否确定完成该作业?";
      }
      this.$confirm(lable, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$api.product
          .FinishedProduceTaskBill({
            produceTaskID: item.produceTaskID,
          })
          .then((res) => {
            this.$message({
              type: "success",
              message: "完成成功!",
            });
            this.getAllMaterils();
          })
          .catch(() => {});
      });
    },

    //撤销完成
    handleRevoke(row){
      this.$confirm('确定要撤销该数据吗？', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$api.product.RevokeFinishedProduceTaskBill({produceTaskID:row.produceTaskID}).then((res)=>{
        this.$message({
              type: "success",
              message: "撤销成功!",
            });
        this.getAllMaterils();
      })
      });

      
    },

    // 删除
    handleDelete(row) {
      this.$confirm("是否删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$api.product
          .DeleteProduceTaskBill({
            produceTaskID: row.produceTaskID,
          })
          .then((res) => {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.getAllMaterils();
          })
          .catch(() => {});
      });
    },

    //作废
    handleCancelCheck(row) {
      this.currentItem = row;
      this.cancelForm.cancelReason = "";
      this.reasonVisible = true;
    },

    // 复制
    handleReCopy(item) {

      let routeUrl = this.$router.resolve({
            path: "/production/productionOrderNewDetail",
            query: {
              produceBillState:item.produceBillState,
              produceTaskBillNo: item.produceTaskBillNo,
              produceTaskID: item.produceTaskID,
              saleOrderNo: item.saleOrderCode,
              taskProduceState:item.taskProduceState,
              productType: item.produceBillType,
              productCode: item.productNo,
              typeStatus: 5,
              },
            });
        window.open(routeUrl.href, '_blank');

      // this.$router.push({
      //   path: "/production/productionOrderNewDetail", // 跳转的路径
      //   query: {
      //     produceTaskBillNo: item.produceTaskBillNo,
      //     produceTaskID: item.produceTaskID,
      //     saleOrderNo: item.saleOrderCode,
      //     productType: item.produceBillType,
      //     productCode: item.productNo,
      //     typeStatus: 5,
      //   },
      // });
    },

    // 停工
    handleStop(item) {
      this.currentItem = item;
      this.cancelForm.stopWorkReason = "";
      this.stopVisible = true;
    },

    Refresh() {
      this.search = this.$options.data().search;
      this.getAllMaterils();
    },
    // 保存表头样式变化
    saveHead(newArray) {
      const parmas = newArray;
      setTimeout(() => {
        this.$api.common.saveTableStyle(parmas).then(() => {});
      }, 300);
    },
    // 保存表头列宽度
    surverWidth(newWidth, oldWidth, column) {
      setTimeout(() => {
        const heads = [...this.tableHead];
        heads.forEach((item) => {
          if (item.columnCode === column.property) {
            item.columnWidth = column.width;
            return;
          }
        });
        this.saveHead(heads);
      }, 100);
    },

    // 获取表格表头
    getTableHead() {
      const parmas = {
        tableCode: this.$config.producetaskbilllist,
      };
      this.$api.common.getAllTableHead(parmas).then((res) => {
        res.sort(arraySort("columnSort"));
        this.tableData.thead = res;
        // this.tableData.thead = res.filter((item)=>{
        //   return item.isForceHide != 1
        // })
        // this.tableData.thead.forEach((item)=>{
        //   if(item.isForceHide == 1){
        //     console.log(item.columnName)
        //   }
        // })
        // console.log(this.tableData.thead)
      });
    },

    // 所有列表数据
    getAllMaterils() {
      const parmas = this.search;
      this.searchLoading = true;
      this.$api.product
        .GetMatchPageProduceTaskBills(parmas)
        .then((res) => {
          res.list.forEach((item) => {
            item.isViod = 0; //作废
            item.isEdit = 0
            item.withdraw = 0; //撤回
            item.isCopy = 0; //复制
            if (item.taskProduceState === 0 && item.produceBillState != 2) {
              item.isViod = 1;
            }
            if (item.produceBillState == 1 && item.taskProduceState == 0) {
              item.withdraw = 1;
            }
            if (
              item.taskProduceState == 3 ||
              (item.produceBillState == 2 && item.produceBillType != 2)
            ) {
              item.isCopy = 1;
            }

            if(item.taskProduceState !=4 && item.produceBillState!=2){
              item.isEdit = 1
            }
          });

          this.search.total = res.totalCount;
          this.tableData.tbody = res.list;
          this.searchLoading = false;
        })
        .catch(() => {
          this.searchLoading = false;
        });
    },
    closeCancelDialog() {
      if (this.$refs.cancelForm) {
        this.$refs.cancelForm.resetFields();
      }
      this.cancelForm = this.$options.data().cancelForm;
    },
  },
};
</script>
<style lang="scss" scoped>
.spot {
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 100%;
}
</style>
<style lang="scss" scoped>
.container {
  height: 100%;
}
.permangeRg {
  border: 1px solid #e6e6e6;
  background: #fff;
  height: 100%;

  .mainTT {
    font-size: 16px;
    font-weight: bold;
    width: 100%;
    padding: 18px 16px;
    padding-bottom: 0;
  }
  .p11 {
    padding: 10px;
  }
}
.warpper {
  height: 100%;
  overflow: hidden;
}
.cardcenter {
  height: 100%;
  width: 100%;
  overflow: hidden;
  .cardList {
    height: 100%;
    overflow: auto;
    background-color: #ebebeb;
    &:last-child {
      margin-right: 0;
    }
    .listitem {
      background: #ffffff;
      color: #999aaa;
      box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.05);
      border-radius: 4px;
      margin-bottom: 10px;
      line-height: 22px;
      border: 1px solid #eeeeee;
      .title {
        color: #333333;
      }
      .time {
        padding: 5px;
        background-color: #f5f6f9;
        &.orgen {
          color: #eeeeee;
          background-color: #f57922;
        }
        &.dred {
          color: #eeeeee;
          background-color: #e13335;
        }
      }
    }
  }
}
.spot {
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 100%;
}
.addWuliaoBox {
  padding: 10px 16px;

  .tableBox {
    margin-top: 16px;
    border: 1px solid #e6e6e6;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    overflow: hidden;
    .bigdialogTable {
      span {
        display: inline-block;
        text-align: center;
        font-weight: bold;
        width: 122px;
      }
    }
    .tt {
      height: 38px;
      line-height: 38px;
      padding-left: 16px;
      background: #f7f8fa;
      border-radius: 8px 8px 0 0;
    }
    .title {
      border-radius: 0;
      border: 1px solid #e6e6e6;
    }
  }
}

.tagCon {
  width: 100%;
  flex: 1;
  overflow-x: hidden;
  border-top: 1px solid #e8e8e8;
  .tagList {
    box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.05);
    border-bottom: 1px solid #e6e6e6;
    .listNav {
      height: 44px;
      padding: 0 14px;
      background: #f7f8fa;
      border-bottom: 1px solid #e6e6e6;
    }
    .tagShow {
      background-color: #ffffff;
    }
  }
}
.subTip {
  border-bottom: 1px #e6e6e6 solid;
  background: #f5f6f9;
  padding: 8px 16px;
}
</style>
